package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.common.entity.PageResult;
import com.atguigu.common.entity.QueryPageBean;
import com.atguigu.dao.TravelItemDao;
import com.atguigu.pojo.TravelItem;
import com.atguigu.service.TravelItemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = TravelItemService.class)
@Transactional
public class TravelItemServiceImpl implements TravelItemService {

    @Autowired
    TravelItemDao travelItemDao;

    @Override
    public void addTravelItem(TravelItem travelItem) {
        travelItemDao.add(travelItem);
    }

    @Override
    public PageResult selectTravelList(QueryPageBean queryPageBean) {
        if (queryPageBean!=null){
            PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
            Page<TravelItem> page = travelItemDao.selectListPage(queryPageBean.getQueryString());
            return new PageResult(page.getTotal(),page.getResult());
        }
        List<TravelItem> travelItems = travelItemDao.selectList();
        return new PageResult(null,travelItems);
    }

    @Override
    public void travelDelete(Integer id) {
        travelItemDao.delete(id);
    }

    @Override
    public void travelEdit(TravelItem travelItem) {
        travelItemDao.travelEdit(travelItem);
    }

    @Override
    public TravelItem selectOne(Integer id) {
        TravelItem travelItem = travelItemDao.selectOne(id);
        return travelItem;
    }

    @Override
    public List<TravelItem> findAll() {
        List<TravelItem> travelItems = travelItemDao.selectList();
        return travelItems;
    }
}
